widgetpaintable: Add a hack to make recursion not infloop
authorBenjamin Otte <otte@redhat.com>
Fri, 6 Jul 2018 08:43:14 +0000 (10:43 +0200)
committerBenjamin Otte <otte@redhat.com>
Fri, 13 Jul 2018 12:56:04 +0000 (14:56 +0200)
Makes the GUADEC talk not crash that I'm supposed to give in 20 minutes.

gtk/gtkwidget.c
gtk/gtkwidgetpaintable.c
gtk/gtkwidgetpaintableprivate.h

index 6f1cdba74a87f38c51259ed438cad4ab01571519..c929701d94d4af05ea9cafb9ca9dc9ea634755bd 100644 (file)
@@ -3803,6 +3803,26 @@ gtk_widget_update_paintables (GtkWidget *widget)
     gtk_widget_paintable_update_image (l->data);
 }
 
+static void
+gtk_widget_push_paintables (GtkWidget *widget)
+{
+  GtkWidgetPrivate *priv = gtk_widget_get_instance_private (widget);
+  GSList *l;
+
+  for (l = priv->paintables; l; l = l->next)
+    gtk_widget_paintable_push_snapshot_count (l->data);
+}
+
+static void
+gtk_widget_pop_paintables (GtkWidget *widget)
+{
+  GtkWidgetPrivate *priv = gtk_widget_get_instance_private (widget);
+  GSList *l;
+
+  for (l = priv->paintables; l; l = l->next)
+    gtk_widget_paintable_pop_snapshot_count (l->data);
+}
+
 /**
  * gtk_widget_queue_draw:
  * @widget: a #GtkWidget
@@ -13134,6 +13154,8 @@ gtk_widget_snapshot (GtkWidget   *widget,
     {
       GskRenderNode *render_node;
 
+      gtk_widget_push_paintables (widget);
+
       render_node = gtk_widget_create_render_node (widget, snapshot);
       /* This can happen when nested drawing happens and a widget contains itself
        * or when we replace a clipped area */
@@ -13142,6 +13164,7 @@ gtk_widget_snapshot (GtkWidget   *widget,
 
       priv->draw_needed = FALSE;
 
+      gtk_widget_pop_paintables (widget);
       gtk_widget_update_paintables (widget);
     }
 
index a57c16416c27a7266bf9741e0f936d17615be180..976b29d2c7d5f9d70dfd81c1e2edbf563605b397 100644 (file)
@@ -58,7 +58,7 @@ struct _GtkWidgetPaintable
   GObject parent_instance;
 
   GtkWidget *widget;
-  guint loop_tracker;
+  guint snapshot_count;
 
   GdkPaintable *current_image;          /* the image that we are presenting */
   GdkPaintable *pending_image;          /* the image that we should be presenting */
@@ -87,7 +87,29 @@ gtk_widget_paintable_paintable_snapshot (GdkPaintable *paintable,
 {
   GtkWidgetPaintable *self = GTK_WIDGET_PAINTABLE (paintable);
 
-  gdk_paintable_snapshot (self->current_image, snapshot, width, height);
+  if (self->snapshot_count > 4)
+    return;
+  else if (self->snapshot_count > 0)
+    {
+      graphene_matrix_t transform;
+
+      gtk_snapshot_push_clip (snapshot,
+                              &GRAPHENE_RECT_INIT(0, 0, width, height));
+      graphene_matrix_init_scale (&transform,
+                                  width / gtk_widget_get_allocated_width (self->widget),
+                                  height / gtk_widget_get_allocated_height (self->widget),
+                                  1.0);
+      gtk_snapshot_push_transform (snapshot, &transform);
+
+      gtk_widget_snapshot (self->widget, snapshot);
+
+      gtk_snapshot_pop (snapshot);
+      gtk_snapshot_pop (snapshot);
+    }
+  else
+    {
+      gdk_paintable_snapshot (self->current_image, snapshot, width, height);
+    }
 }
 
 static GdkPaintable *
@@ -366,3 +388,16 @@ gtk_widget_paintable_update_image (GtkWidgetPaintable *self)
   g_set_object (&self->pending_image, pending_image);
   g_object_unref (pending_image);
 }
+
+void
+gtk_widget_paintable_push_snapshot_count (GtkWidgetPaintable *self)
+{
+  self->snapshot_count++;
+}
+
+void
+gtk_widget_paintable_pop_snapshot_count (GtkWidgetPaintable *self)
+{
+  self->snapshot_count--;
+}
+
index e971251abc71081568ae60b6950c662cfad0bd3b..381d28a8062639eceaa926337cfdf6d962a8984a 100644 (file)
@@ -25,5 +25,7 @@
 
 void            gtk_widget_paintable_update_image               (GtkWidgetPaintable     *self);
 
+void            gtk_widget_paintable_push_snapshot_count        (GtkWidgetPaintable     *self);
+void            gtk_widget_paintable_pop_snapshot_count         (GtkWidgetPaintable     *self);
 
 #endif /* __GTK_WIDGET_PAINTABLE_PRIVATE_H__ */